/*      $Id: HTTPSocket.java 799 2008-08-23 18:56:37Z phrakt $    */
/*
 * Copyright (c) 2007 Jean-Francois Brousseau <phrakt@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package ca.terraquati.canopy.http;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import java.io.IOException;


/**
 * An interface to represent stream sockets that are used strictly for
 * exchanging HTTP messages.
 *
 *
 * @author Jean-Fran&ccedil;ois Brousseau
 */
public interface HTTPSocket
{
	/**
	 * Closes the socket represented by this object.
	 *
	 */
	public void close()
	    throws IOException;

	/**
	 * Retrieves the HTTP session object associated with the socket
	 * represented by this object.
	 *
	 */
	public HTTPSession getSession();

	/**
	 * Checks whether the socket represented by this object is currently
	 * closed.
	 *
	 * @return <code>true</code> if the socket is connected,
	 *         <code>false</code> otherwise
	 */
	public boolean isClosed();

	/**
	 * Checks whether the socket represented by this object is currently
	 * connected.
	 *
	 * @return <code>true</code> if the socket is connected,
	 *         <code>false</code> otherwise
	 */
	public boolean isConnected();

	public int recv(byte[] data)
	    throws IOException;

	public int recv(byte[] data, int length)
	    throws IOException;

	/**
	 * Sends the serialized equivalent of the HTTP message object
	 * <code>msg</code> over the socket represented by this object.
	 *
	 * @return	the total number of bytes sent on success, or -1 on failure
	 */
	public int recvmsg(HTTPMessage msg)
	    throws IOException;

	/**
	 *
	 */
	public int send(byte[] data)
	    throws IOException;

	public int send(byte[] data, int length)
	    throws IOException;

	public int send(byte[] data, int length, final long timeout)
	    throws IOException;

	public int sendmsg(HTTPMessage msg)
	    throws IOException;
};
